<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Upload Multiple Files with FormData</title>
</head>

<body>
    <input type="file" id="fileInput" multiple>
    <button onclick="uploadFiles()">上传文件</button>

    <script>
        function uploadFiles() {
            const fileInput = document.getElementById('fileInput');
            const files = fileInput.files;

            const formData = new FormData();
            // 将每个文件添加到 FormData 对象中
            for (let i = 0; i < files.length; i++) {
                formData.append('files', files[i]);
            }

            // 使用 fetch API 发送请求
            fetch('localhost:8080/file/uploadfils', {
                method: 'POST',
                body: formData
            })
              .then(response => response.json())
              .then(data => console.log(data))
              .catch(error => console.error('Error:', error));
        }
    </script>
</body>

</html>